﻿using MediatR;
using MyMES.Domain.zmc;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Read.API.Application.Commends.Customers;

namespace MyMES.Read.API.Application.CommendHandlers.Customers
{
    public class GetCustomertypeCommendHandlers : IRequestHandler<GetCustomertypeCommends, APIResult<List<CustomerTypes>>>
    {
        private readonly IBaseRepository<CustomerTypes> customertypeRepository;

        public GetCustomertypeCommendHandlers(IBaseRepository<CustomerTypes> customertypeRepository)
        {
            this.customertypeRepository = customertypeRepository;
        }

        /// <summary>
        /// 获取客户类型
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<List<CustomerTypes>>> Handle(GetCustomertypeCommends request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<List<CustomerTypes>> result = new APIResult<List<CustomerTypes>>();
                result.Code = APIEnum.查询成功;
                result.Msg = "查询成功";
                string sql = "SELECT * FROM customerTypes";
                var list = await customertypeRepository.SelectAsync(sql);
                result.data = list;
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
